package com.flying.flow.service;

import java.util.Date;

import com.flying.common.annotation.DaoCreate;
import com.flying.common.annotation.DaoQuery;
import com.flying.common.annotation.DaoRemove;
import com.flying.common.util.Codes;
import com.flying.flow.model.TaskParticipant;
import com.flying.framework.annotation.MethodInfo;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.context.ServiceContext;
import com.flying.framework.model.ActionResult;
import com.flying.framework.model.ModelFactory;
import com.flying.framework.model.QueryResult;
import com.flying.framework.security.Principal;
import com.flying.framework.service.AbstractService;

@Service(value="TaskParticipantService", desc="任务参与者")
public class TaskParticipantService extends AbstractService{
        
	@MethodInfo("新增")
	public TaskParticipant create(
			@Param(value=TaskParticipant.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=TaskParticipant.PARTICIPANT_ID, required=true,	desc="参与者ID") String participant_id,
			@Param(value=TaskParticipant.PARTICIPANT_NAME, required=false,	desc="参与者名称") String participant_name
		) throws Exception {
		return this.create2(task_id, participant_id, participant_name, null, null);
	}
    
	@MethodInfo("新增")
	@DaoCreate(entity=TaskParticipant.ENTITY_NAME)
	protected TaskParticipant create2(
			@Param(value=TaskParticipant.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=TaskParticipant.PARTICIPANT_ID, required=true,	desc="参与者ID") String participant_id,
			@Param(value=TaskParticipant.PARTICIPANT_NAME, required=false,	desc="参与者名称") String participant_name,
			@Param(value=TaskParticipant.CREATOR, required=false,	desc="创建人") String creator,
			@Param(value=TaskParticipant.CREATE_TIME, required=false,	desc="创建时间") Date create_time
		) throws Exception {
		Principal p = ServiceContext.getContext().getPrincipal();
		return ModelFactory.create(TaskParticipant.class, 
				TaskParticipant.CREATOR, (p == null?null: p.getName()),
				TaskParticipant.CREATE_TIME, new Date());
	}

	@MethodInfo("删除")
	@DaoRemove(entity=TaskParticipant.ENTITY_NAME)
	public ActionResult remove(
			@Param(value=TaskParticipant.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=TaskParticipant.PARTICIPANT_ID, required=true,	desc="参与者ID") String participant_id
		) throws Exception {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=TaskParticipant.ENTITY_NAME, pageable=true, modelClass=TaskParticipant.class)
	public QueryResult<TaskParticipant> findByTaskId(
			@Param(value=TaskParticipant.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) throws Exception {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=TaskParticipant.ENTITY_NAME, pageable=true, modelClass=TaskParticipant.class)
	public QueryResult<TaskParticipant> findByParticipantId(
			@Param(value=TaskParticipant.PARTICIPANT_ID, required=true,	desc="参与者ID") String participant_id,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) throws Exception {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=TaskParticipant.ENTITY_NAME, single=true, throwsNotFoundException=true )
	public TaskParticipant findById(
			@Param(value=TaskParticipant.TASK_ID, required=true,	desc="任务ID") Long task_id,
			@Param(value=TaskParticipant.PARTICIPANT_ID, required=true,	desc="参与者ID") String participant_id
		) throws Exception {
		return null;
	}

}